package com.lgf.vo;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import cn.hutool.core.io.FileUtil;

public enum CodeFileTypeEnum {
	HTML("HTML", new String[] { "HTML", "HTM" }), PHP("PHP", new String[] { "PHP" }), JS("JS", new String[] { "JS" }),
	CSS("CSS", new String[] { "CSS" });

	private String text;
	/**
	 * 后缀名
	 */
	private String[] suffixs;

	private CodeFileTypeEnum(String text, String[] suffixs) {
		this.text = text;
		this.suffixs = suffixs;
	}

	public static CodeFileTypeEnum getType(String type) {
		for (CodeFileTypeEnum te : CodeFileTypeEnum.values()) {
			if (te.text.equals(type)) {
				return te;
			}
		}
		return null;
	}

	public static Set<String> getTypes() {
		Set<String> types = new HashSet<String>();
		for (CodeFileTypeEnum te : CodeFileTypeEnum.values()) {
			types.add(te.getText());
		}
		return types;
	}

	/**
	 * 返回文件类型
	 * 
	 * @author zhouz
	 * @date 2019年11月20日
	 * 
	 * @param file
	 * @return
	 */
	public static CodeFileTypeEnum getType(File file) {
		for (CodeFileTypeEnum te : CodeFileTypeEnum.values()) {
			for (String suffix : te.suffixs) {
				if (FileUtil.pathEndsWith(file, suffix.toLowerCase())) {
					return te;
				}
			}
		}
		return null;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String[] getSuffixs() {
		return suffixs;
	}

	public void setSuffixs(String[] suffixs) {
		this.suffixs = suffixs;
	}

}
